﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>key</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>
<P><FONT face=Courier>sự kiện khi keydown - demo này sẽ hiện lên một hộp thoại 
Yes /&nbsp;No</FONT></P>
<P><FONT face=Courier>@Override<BR>public boolean <STRONG>onKeyDown</STRONG>  (int keyCode, 
KeyEvent event) {<BR>&nbsp;//Handle the back button<BR>&nbsp;if(keyCode == KeyEvent.KEYCODE_BACK || keyCode == 
    KeyEvent.KEYCODE_HOME ) 
{<BR>&nbsp;&nbsp;//Ask the user if they want to quit<BR>&nbsp;&nbsp;new 
AlertDialog.Builder(this)<BR>&nbsp;&nbsp;&nbsp;.setIcon(android.R.drawable.ic_dialog_alert)<BR>&nbsp;&nbsp;&nbsp;.setTitle("Confirm")<BR>&nbsp;&nbsp;&nbsp;.setMessage("Do 
you really want to exit?")<BR>&nbsp;&nbsp;&nbsp;.setPositiveButton(R.string.yes, 
new DialogInterface.OnClickListener() 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR>&nbsp;&nbsp;&nbsp;&nbsp;public void 
onClick(DialogInterface dialog, int which) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Stop the 
activity<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;saveResume();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finish(); 
<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;})<BR>&nbsp;&nbsp;.setNegativeButton(R.string.no, 
null)<BR>&nbsp;&nbsp;.show();<BR>&nbsp;&nbsp;return true;<BR>&nbsp;}else 
{<BR>&nbsp;&nbsp;return super.onKeyDown(keyCode, 
event);<BR>&nbsp;}<BR>}</FONT></P></body>
</html>
